package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.LeaseTermService;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/payment")
@Tag(name = "支付方式管理")
public class PaymentTypeController {
    /*
     * 实体类（Model模块里）->Web-admin写Mapper、Service、Controller
     * */
    @Autowired
    private PaymentTypeService paymentTypeService;


    @GetMapping("/list")
    @Operation(summary = "查询所有支付方式")
    public Result<List<PaymentType>> showAll() {

        List<PaymentType> list = paymentTypeService.list();
        return Result.ok(list);
    }

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "保存或更新支付方式")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType) {

        boolean b = paymentTypeService.saveOrUpdate(paymentType);
        return b?Result.ok():Result.fail();
    }

    @DeleteMapping("/deleteById")
    @Operation(summary = "根据id删除支付方式")
    public Result deleteById(@RequestParam Long id) {

        boolean b = paymentTypeService.removeById(id);
        return b?Result.ok():Result.fail();
    }
}
